<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload=function () {
            var p=document.getElementsByClassName("example")[0];
            p.style.background = "red";
            p.style.color = "green";
            alert(p.style.background)
            alert(p.style.color)
        }
    </script>
</head>
<body>
    <p class="example">
        这是个P标签
    </p>
</body>
</html>